package com.baidu.thirdlib.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import com.baidu.thirdlib.BaseActivity;
import com.baidu.thirdlib.R;
import com.baidu.thirdlib.adpater.LibAdapter;
import com.baidu.thirdlib.constants.Lib;
import com.kvin.toolkit.utils.JumpUtils;
import com.slidingmenu.SlidingMenu;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends BaseActivity {
    private long currentTime;
    @BindView(R.id.lib_list)
    ListView libList;

    private LibAdapter mAdapter;
    private ArrayList<String> libItems;

    private SlidingMenu mMenu;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
    }


    @Override
    public void init() {
        initMenu();
        libItems = Lib.getLibList();
        mAdapter = new LibAdapter(libItems, this);
        libList.setAdapter(mAdapter);
        libList.setOnItemClickListener(mOnItemClickListener);

    }


    @Override
    public void initNav() {
        setTitle("Main");
    }

    private void initMenu() {
        mMenu = new SlidingMenu(this);
        mMenu.setMode(SlidingMenu.LEFT);
        mMenu.setBehindOffset(200);
        mMenu.setMenu(R.layout.menu_left);
        mMenu.attachToActivity(this, SlidingMenu.SLIDING_WINDOW);
        mMenu.showMenu();
        mMenu.toggle();
    }

    /**
     * item click event
     */
    public AdapterView.OnItemClickListener mOnItemClickListener = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            switch (libItems.get(position)) {
                case Lib.MAP_LIB:
                    JumpUtils.simpleJump(MainActivity.this, MapActivity.class);
                    break;
                case Lib.SMS_LIB:
                    JumpUtils.simpleJump(MainActivity.this, SMSActivity.class);
                    break;
                case Lib.JPUSH_LIB:
                    JumpUtils.simpleJump(MainActivity.this, JPushActivity.class);
                    break;
                case Lib.SHARE_LIB:
                    JumpUtils.simpleJump(MainActivity.this, ShareActivity.class);
                    break;
                case Lib.TOOL_LIB:
                    JumpUtils.simpleJump(MainActivity.this, ToolKitActivity.class);
                    break;
                case Lib.UNION_LIB:
                    JumpUtils.simpleJump(MainActivity.this, UnionActivity.class);
                    break;
            }
        }
    };


    @Override
    public void onBackPressed() {
        if (System.currentTimeMillis() - currentTime < 1000) {
            finish();
        }
        currentTime = System.currentTimeMillis();
        Toast.makeText(MainActivity.this, "再按一次 退出程序", Toast.LENGTH_SHORT).show();
    }
}
